/**
 * ======================================
 * 配置管理
 * author: SKY-D
 * file: index.vue
 * date: 2022/6/16 22:25
 * ======================================
 */
<template>
  <page :list="false">
    <el-form slot="where" ref="form" label-width="280px">
      <el-form-item label="楼宇码有效时间（分钟）">
        <el-input-number v-model="form.building_qrcode_time" class="k-width-200-p" :min="1" :max="14400" label="有效时间，单位分钟" @change="handleChange" />
      </el-form-item>
      <el-form-item label="企业码有效时间（分钟）">
        <el-input-number v-model="form.company_qrcode_time" class="k-width-200-p" :min="1" :max="14400" label="有效时间，单位分钟" @change="handleChange" />
      </el-form-item>
      <el-form-item label="用户码有效时间（分钟）">
        <el-input-number v-model="form.user_qrcode_time" class="k-width-200-p" :min="1" :max="14400" label="有效时间，单位分钟" @change="handleChange" />
      </el-form-item>
      <el-form-item label="社会面调查管理">
        <el-select v-model="form.type" class="k-width-200-p" placeholder="请选择" @change="handleChange">
          <el-option label="省" value="province" />
          <el-option label="市" value="city" />
          <el-option label="区" value="area" />
          <el-option label="街道" value="street" />
        </el-select>
      </el-form-item>
    </el-form>
  </page>
</template>

<script>
import { getQrcode, setQrcode, getFlow, setFlow } from '@/api/system'
import Page from '@/layout/page'
export default {
  name: 'User',
  components: { Page },
  data() {
    return {
      form: {
        'building_qrcode_time': '',
        'company_qrcode_time': '',
        'user_qrcode_time': '',
        'type': ''
      },
      timer: ''
    }
  },
  mounted() {
    this.getData()
  },
  methods: {
    getData() {
      getQrcode().then(res => {
        const data = res.data
        for (const formKey in this.form) {
          if (data[formKey]) {
            this.form[formKey] = data[formKey]
          }
        }
      })
      getFlow().then(res => {
        const data = res.data
        for (const formKey in this.form) {
          if (data[formKey]) {
            this.form[formKey] = data[formKey]
          }
        }
      })
    },
    handleChange() {
      console.log('选择了', this.form)
      if (this.timer) {
        clearTimeout(this.timer)
      }
      this.timer = setTimeout(() => {
        this.handleSave()
      }, 1000)
    },
    async handleSave() {
      await setQrcode(this.form)
      await setFlow(this.form)
      this.$notify.success('保存成功')
    }
  }
}
</script>
